/*
* Copyright 2017 Yonyou Auto Information Technology（Shanghai） Co., Ltd. All Rights Reserved.
*
* This software is published under the terms of the YONYOU Software
* License version 1.0, a copy of which has been included with this
* distribution in the LICENSE.txt file.
*
* @Project Name : marketing-service-showroom
*
* @File name : ShowRoomController.java
*
* @Author : Administrator
*
* @Date : 2017年11月13日
*
----------------------------------------------------------------------------------
*     Date       Who       Version     Comments
* 1. 2017年11月13日    Administrator    1.0
*
*
*
*
----------------------------------------------------------------------------------
*/

package com.yonyou.gmmc.service.showroom.controller;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.marketing.common.constants.ResultMsgConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import org.marketing.common.Response;
import com.yonyou.gmmc.service.showroom.constant.ShowroomConstant;
import com.yonyou.gmmc.service.showroom.model.TmModel;
import com.yonyou.gmmc.service.showroom.service.ShowRoomService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @author Administrator TODO description
 * @date 2017年11月13日
 */
@RestController
@RequestMapping(value = ShowroomConstant.BASE_PATH + "/" + ShowroomConstant.VERSION)
@Api("车型展厅相关API")
public class ShowRoomController {

	private Logger logger = Logger.getLogger(ShowRoomController.class);

	@Autowired
	private ShowRoomService showRoomService;

	/**
	 * @author 根据品牌code或查询所有品牌车系数据
	 * @date 2017年11月20日
	 * @return
	 */
	@RequestMapping(value = "/brands", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "根据品牌code或查询所有品牌车系数据", notes = "根据品牌code或查询所有品牌车系数据")
	public Response<List<Map<String, Object>>> getBrandExhibitionData(@RequestParam(required=false) String brandCode
			,@RequestParam(required=false) String seriesCode) {
		logger.info("ShowRoomController.getBrandExhibitionData==>start...");
		try {
			List<Map<String, Object>> dtos = showRoomService.getBrandExhibitionData(brandCode,seriesCode);
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, dtos, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		} finally {
			logger.info("ShowRoomController.getBrandExhibitionData==>end...");
		}
	}
	/**
	 * @author 根据车系code查询所有车型以及车型的配置
	 * @date 2017年11月20日
	 * @param seriesCode
	 * @return
	 */
	@RequestMapping(value = "/seriesGroup", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "根据车系code查询所有车型以及车型的配置", notes = "根据车系code查询所有车型以及车型的配置")
	public Response<List<Map<String, Object>>> getSeriesGroup(@RequestParam(required=true) String seriesCode
			,@RequestParam(required=false) String displacement
			,@RequestParam(required=false) String gearboxType) {
		logger.info("ShowRoomController.getSeriesExhibitionData==>start...");
		try {
			List<Map<String, Object>> list = showRoomService.getSeriesGroup(seriesCode,displacement,gearboxType);
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, list, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		} finally {
			logger.info("ShowRoomController.getSeriesExhibitionData==>end...");
		}
	}
	/**
	 * @author 根据车系code查询所有车型以及车型的配置
	 * @date 2017年11月20日
	 * @param seriesCode
	 * @return
	 */
	@RequestMapping(value = "/packages", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "根据车系code查询所有车型以及车型的配置", notes = "根据车系code查询所有车型以及车型的配置")
	public Response<TmModel> getSeriesExhibitionData(@RequestParam("packageCode") String packageCode) {
		logger.info("ShowRoomController.getSeriesExhibitionData==>start...");
		try {
			TmModel list = showRoomService.getSeriesExhibitionData(packageCode);
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, list, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		} finally {
			logger.info("ShowRoomController.getSeriesExhibitionData==>end...");
		}
	}

}
